package org.arch_learn.dubbo_demo.service_consumer;

import org.apache.dubbo.common.URL;
import org.apache.dubbo.common.extension.ExtensionLoader;
import org.apache.dubbo.registry.Registry;
import org.apache.dubbo.registry.RegistryFactory;

public class DubboRouterMain {
    public static void main(String[] args) {
        RegistryFactory registryFactory = ExtensionLoader.getExtensionLoader(RegistryFactory.class).getAdaptiveExtension();
        Registry registry = registryFactory.getRegistry(URL.valueOf("zookeeper://127.0.0.1:2181"));
        //condition://还可以为script://，可拓展，必填
        //category=routers表示该数据为动态配置类型，为必填项
        //dynamic=false表示非动态（路由规则注册后不可变更），注册中心持久化路由规则，为必填项
        //force=true表示路由规则结果为空是是否强制执行，非必填项
        registry.register(URL.valueOf("condition://0.0.0.0/org.arch_learn.dubbo_demo.api.HelloService?category=routers&force=true&dynamic=true&rule=" +
                //这里注意rule里面的空格
//                URL.encode("=> port != 20901")
                URL.encode("=> port = *")
        )
    );
//        registry.unregister(URL.valueOf("condition://0.0.0.0/org.arch_learn.dubbo_demo.api.HelloService?category=routers&force=true&dynamic=true&rule=" +
//                //这里注意rule里面的空格
//                URL.encode("=> port != 20901")));
    }
}
